﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter05
{
    public class Code03
    {
        public static void Begin()
        {
            //字符串转字符数组
            {
                string myString = "A string";
                char[] myChar = myString.ToCharArray();
                foreach (char characher in myString)
                {
                    Console.WriteLine("{0}", characher);
                }
            }
            //字符串长度  
            {
                string myString = Console.ReadLine();
                Console.WriteLine("You tpyeed {0} characters.", myString.Length);
            }
            //字符串转小写
            {
                string userResponse = Console.ReadLine();
                if (userResponse.ToLower() == "yes")
                {
                    Console.WriteLine(userResponse);
                }
            }
            //字符串转小写去空格
            {
                string userResponse = Console.ReadLine();
                userResponse = userResponse.ToLower();
                userResponse = userResponse.Trim();
                if (userResponse.ToLower() == "yes")
                {
                    Console.WriteLine(userResponse);
                }
            }
            //字符串删除指定字符
            {
                char[] trimChars = { ' ', 'e', 's' };
                string userResponse = Console.ReadLine();
                userResponse = userResponse.ToLower();
                userResponse = userResponse.Trim(trimChars);
                if (userResponse == "y")
                {
                    Console.WriteLine(userResponse);
                }
            }
            //字符串前填充
            {
                string myString = "Aligned";
                myString = myString.PadLeft(10);
                Console.WriteLine(myString);
                Console.ReadLine();
            }
            //字符串后填充
            {
                string myString = "Aligned";
                myString = myString.PadRight(10, '-');
                Console.WriteLine(myString);
                Console.ReadLine();
            }
        }

        public static void BeginEx05()
        {
            //IDE 自动完成
            string myString = "This is a test.";
            char[] separator = { ' ' };
            string[] myWords;
            myWords = myString.Split(separator);
            foreach (string word in myWords)
            {
                Console.WriteLine("{0}", word);
            }
            Console.ReadLine();
        }
    }
}
